package com.ysm.smfu.adapter;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ysm.smfu.MainActivity;
import com.ysm.smfu.R;
import com.ysm.smfu.activity.CategoryActivity;
import com.ysm.smfu.activity.FoundActivity;
import com.ysm.smfu.food.FoodCategoryActivity;
import com.ysm.smfu.food.FoodMainActivity;
import com.ysm.smfu.utils.ToastUtils;
import com.ysm.smfu.utils.UIUtils;

/**
 * Created by Administrator on 2016/11/7.
 */
public class MyFoodGridAdapter extends BaseAdapter {

    private final String[] names;
    private final int[] ims;
    private final String[] ids;
    private final FragmentActivity fragmentActivity;

    public MyFoodGridAdapter(String[] category_name2, int[] category_ims2, String[] category_id2, FragmentActivity fragmentActivity) {
        names = category_name2;
        ims = category_ims2;
        ids = category_id2;
        this.fragmentActivity = fragmentActivity;
    }

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        View view1 = View.inflate(UIUtils.getContext(), R.layout.item_category_item, null);
        ImageView imageView = (ImageView) view1.findViewById(R.id.item_category_img);
        TextView text = (TextView) view1.findViewById(R.id.item_category_text);
        imageView.setImageResource(ims[i]);
        text.setText(names[i]);
        view1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                searchForCategory(ids[i], names[i]);
            }
        });
        return view1;
    }

    /**
     * 分类搜索
     */
    private void searchForCategory(String id, String type) {
        Intent intent = new Intent(UIUtils.getContext(), FoodCategoryActivity.class);
        fragmentActivity.startActivity(intent);
    }
}

